Skip to content

[IR] Remove size argument from lifetime intrinsics #150248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jul 23, 2025

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).

Copy link

github-actions bot commented Jul 23, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@nikic nikic force-pushed the lifetime-size branch 2 times, most recently from a56aec7 to ef647f8 Compare July 25, 2025 15:18
@nikic nikic marked this pull request as ready for review July 25, 2025 15:25
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AArch64 backend:AMDGPU backend:MIPS backend:RISC-V backend:PowerPC backend:SystemZ backend:WebAssembly backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. llvm:codegen llvm:globalisel mlir:llvm PGO Profile Guided Optimizations mlir flang Flang issues not falling into any other category llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes backend:SPIR-V backend:NVPTX coroutines C++20 coroutines llvm:SelectionDAG SelectionDAGISel as well compiler-rt:sanitizer flang:fir-hlfir llvm:ir llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Jul 25, 2025
nikic added a commit to nikic/llvm-project that referenced this pull request Aug 4, 2025
Split out from llvm#150248:

Since llvm#150944 the size passed to lifetime.start/end is considered
meaningless. The lifetime always applies to the whole alloca.

This adjusts MemoryLocation to determine the MemoryLocation size
from the alloca size, instead of using the argument.
nikic added a commit that referenced this pull request Aug 5, 2025
Split out from #150248:

Since #150944 the size passed to lifetime.start/end is considered
meaningless. The lifetime always applies to the whole alloca.

Accordingly remove handling for size mismatch in the StackLifetime
analysis.
nikic added a commit that referenced this pull request Aug 5, 2025
Split out from #150248:

Since #150944 the size passed to lifetime.start/end is considered
meaningless. The lifetime always applies to the whole alloca.

This adjusts MemoryLocation to determine the MemoryLocation size from
the alloca size, instead of using the argument.
nikic added a commit to nikic/llvm-project that referenced this pull request Aug 5, 2025
Split out from llvm#150248:

Use the size of the alloca instead of the size passed to the
lifetime intrinsic.

As a bonus, this handles dynamic allocas correctly (see the added
test) instead of doing a memset with size -1...
nikic added a commit that referenced this pull request Aug 5, 2025
Split out from #150248:

Since #150944 the size passed to lifetime.start/end is considered
meaningless. The lifetime always applies to the whole alloca.

Accordingly, remove checks of the lifetime size from MemCpyOpt.
nikic added a commit to nikic/llvm-project that referenced this pull request Aug 7, 2025
Split out from llvm#150248:

Use the size of the alloca instead of the size passed to the
lifetime intrinsic.

As a bonus, this handles dynamic allocas correctly (see the added
test) instead of doing a memset with size -1...
@nikic
Copy link
Contributor Author

nikic commented Aug 7, 2025

I think this is now ready for review if you ignore the first commit (which is #152154).

nikic added a commit that referenced this pull request Aug 7, 2025
Split out from #150248:

Use the size of the alloca instead of the size passed to the lifetime
intrinsic.

As a bonus, this handles dynamic allocas correctly (see the added test)
instead of doing a memset with size -1...
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 7, 2025
…154)

Split out from llvm/llvm-project#150248:

Use the size of the alloca instead of the size passed to the lifetime
intrinsic.

As a bonus, this handles dynamic allocas correctly (see the added test)
instead of doing a memset with size -1...
Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming there aren't any non-trivial changes to the regression tests. (I looked at the code changes, but I skimmed the test changes.)

Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Now that llvm#149310 has restricted lifetime intrinsics to only work
on allocas, we can also drop the explicit size argument. Instead,
the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca
alive/dead. We never used that capability, so we should remove the
need to handle that possibility everywhere (many key places, including
stack coloring, did not actually respect this).
@nikic nikic merged commit c23b4fb into llvm:main Aug 8, 2025
12 checks passed
@nikic nikic deleted the lifetime-size branch August 8, 2025 09:09
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 8, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building clang,flang,llvm,mlir at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/25074

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: Bindings/llvm-c/echo.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as < /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Bindings/llvm-c/echo.ll | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-dis > /Users/buildbot/buildbot-root/aarch64-darwin/build/test/Bindings/llvm-c/Output/echo.ll.tmp.orig # RUN: at line 1
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-dis
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as < /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Bindings/llvm-c/echo.ll | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-c-test --echo > /Users/buildbot/buildbot-root/aarch64-darwin/build/test/Bindings/llvm-c/Output/echo.ll.tmp.echo # RUN: at line 2
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-c-test --echo
Assertion failed: ((Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"), function init, file Instructions.cpp, line 756.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as
 #0 0x00000001045ec04c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10028004c)
 #1 0x00000001045ea010 llvm::sys::RunSignalHandlers() (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10027e010)
 #2 0x00000001045ecb48 SignalHandler(int, __siginfo*, void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100280b48)
 #3 0x000000019f823584 (/usr/lib/system/libsystem_platform.dylib+0x18047b584)
 #4 0x000000019f7f2c20 (/usr/lib/system/libsystem_pthread.dylib+0x18044ac20)
 #5 0x000000019f6ffa30 (/usr/lib/system/libsystem_c.dylib+0x180357a30)
 #6 0x000000019f6fed20 (/usr/lib/system/libsystem_c.dylib+0x180356d20)
 #7 0x00000001047cffd8 llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>, llvm::Twine const&) (.cold.5) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100463fd8)
 #8 0x00000001044e8f94 llvm::InvokeInst::init(llvm::FunctionType*, llvm::Value*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>, llvm::Twine const&) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10017cf94)
 #9 0x00000001043a61e8 llvm::CallInst::Create(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>, llvm::Twine const&, llvm::InsertPosition) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10003a1e8)
#10 0x00000001044e0794 llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>, llvm::Twine const&, llvm::MDNode*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100174794)
#11 0x00000001044decc4 llvm::IRBuilderBase::createCallHelper(llvm::Function*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::FMFSource, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100172cc4)
#12 0x00000001044def5c llvm::IRBuilderBase::CreateLifetimeEnd(llvm::Value*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100172f5c)
#13 0x0000000104446ef4 llvm::UpgradeIntrinsicCall(llvm::CallBase*, llvm::Function*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x1000daef4)
#14 0x0000000104453720 llvm::UpgradeCallsToIntrinsic(llvm::Function*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x1000e7720)
#15 0x000000010437aa48 llvm::LLParser::validateEndOfModule(bool) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10000ea48)
#16 0x0000000104379984 llvm::LLParser::Run(bool, llvm::function_ref<std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> (llvm::StringRef, llvm::StringRef)>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10000d984)
#17 0x00000001043bccf0 parseAssemblyInto(llvm::MemoryBufferRef, llvm::Module*, llvm::ModuleSummaryIndex*, llvm::SMDiagnostic&, llvm::SlotMapping*, bool, llvm::function_ref<std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> (llvm::StringRef, llvm::StringRef)>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100050cf0)
#18 0x00000001043bcf5c parseAssemblyWithIndex(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*, bool, llvm::function_ref<std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> (llvm::StringRef, llvm::StringRef)>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100050f5c)
#19 0x00000001043bd13c parseAssemblyFileWithIndex(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*, bool, llvm::function_ref<std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> (llvm::StringRef, llvm::StringRef)>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x10005113c)
#20 0x00000001043bcfe0 llvm::parseAssemblyFileWithIndex(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*, llvm::function_ref<std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> (llvm::StringRef, llvm::StringRef)>) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x100050fe0)
#21 0x000000010436f4e8 main (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-as+0x1000034e8)
#22 0x000000019f467154
Error with new bitcode parser: file too small to contain bitcode header

--

********************


maurer added a commit to maurer/rust that referenced this pull request Aug 8, 2025
In llvm/llvm-project#150248 LLVM removed the size parameter from the
lifetime format. Tolerate not having that size parameter.
maurer added a commit to maurer/rust that referenced this pull request Aug 8, 2025
In llvm/llvm-project#150248 LLVM removed the size parameter from the
lifetime format. Tolerate not having that size parameter.
maurer added a commit to maurer/rust that referenced this pull request Aug 8, 2025
In llvm/llvm-project#150248 LLVM removed the size parameter from the
lifetime format. Tolerate not having that size parameter.
maurer added a commit to maurer/rust that referenced this pull request Aug 8, 2025
In llvm/llvm-project#150248 LLVM removed the size parameter from the
lifetime format. Tolerate not having that size parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 backend:AMDGPU backend:MIPS backend:NVPTX backend:PowerPC backend:RISC-V backend:SPIR-V backend:SystemZ backend:WebAssembly backend:X86 backend:Xtensa clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category compiler-rt:sanitizer coroutines C++20 coroutines flang:fir-hlfir flang Flang issues not falling into any other category llvm:analysis Includes value tracking, cost tables and constant folding llvm:codegen llvm:globalisel llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:ir llvm:SelectionDAG SelectionDAGISel as well llvm:transforms mlir:llvm mlir PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants